package com.itheima.health.controller;

import com.itheima.health.entity.Result;
import com.itheima.health.service.OrderSettingService;
import com.itheima.health.utils.poi.POIUtils;
import io.swagger.annotations.Api;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;


@RestController
@Api(tags = "预约管理开发")  // 作用在类上
@RequestMapping("ordersetting")
public class OrderSettingController {
    @Reference
    private OrderSettingService orderSettingService;

    @PostMapping("importOrderSettings")
    public Result  importOrderSettings(@RequestParam("excelFile")MultipartFile file){
        //  file   excel  file ----  List ----service--  批量录入 mp 优化--db
        List<String[]> orderSettingList = null;
        try {
            orderSettingList = POIUtils.readExcel(file);
        } catch (IOException e) {
            e.printStackTrace();
        }
        orderSettingService.importOrderSettings(orderSettingList);
        return new Result(true);
    }


    @GetMapping("findSettingData/{year}/{month}")
    public Result findSettingData(@PathVariable int year, @PathVariable int month){
        return new Result(orderSettingService.findSettingData(year,month));
    }

    @PutMapping("updateNumberByOrderdate/{number}/{orderdate}")
    public Result updateNumberByOrderdate(@PathVariable("number") int number,@PathVariable("orderdate") String orderdate){
        return new Result(orderSettingService.updateNumberByOrderdate(number,orderdate));
    }


}
